home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
System Booster
/
System Booster.iso
/
Commodities
/
CxCommander
/
CxCommander.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-09-26
|
5KB
|
215 lines
/*
** CxComander.c by Miloslaw "Thorgal" Smyk
**
** Loosely based on CxKiller by Gael Marziou.
** This program ables you to send CxMessages to
** specified Commodities.
**
** Don't hesitate to use this code as you wish.
** (and please be overlooking with bugs :-) )
**
** Coded on Sunday, 22 May 1994.
*/
#define VERSION "1.0 (22.5.94)"
#include <exec/memory.h>
#include <proto/dos.h>
#include <proto/commodities.h>
#include <proto/exec.h>
#include <string.h>
/*** private functions of "commodities.library" ***/
#pragma libcall CxBase FindBroker 6c 801
#pragma libcall CxBase CopyBrokerList ba 801
#pragma libcall CxBase FreeBrokerList c0 801
#pragma libcall CxBase BrokerCommand c6 802
CxObj *FindBroker(char *);
LONG CopyBrokerList(struct List *);
LONG FreeBrokerList(struct List *);
LONG BrokerCommand(char *, LONG id);
/*** private structures & defines ***/
struct BrokerCopy {
struct Node bc_Node;
char bc_Name[CBD_NAMELEN];
char bc_Title[CBD_TITLELEN];
char bc_Descr[CBD_DESCRLEN];
LONG bc_Task;
LONG bc_Dummy1;
LONG bc_Dummy2;
UWORD bc_Flags;
};
#define COF_ACTIVE 2
/*** prototyping made easy ***/
void TellAllBrokers(LONG);
void TellOneBroker(char *, LONG);
#define TEMPLATE "CXCOMMAND,CXNAME/M,ALL/S,SHOW/S,HELP/S"
#define OPT_COMMAND 0
#define OPT_NAME 1
#define OPT_ALL 2
#define OPT_SHOW 3
#define OPT_HELP 4
#define OPT_COUNT 5
char HelpString[]="\x1b[41m\x1b[32mCxCommander " VERSION " by W.F.M.H.\n\
\x1b[0m\x1b[1m\x1b[33mWritten by Miloslaw 'Thorgal' Smyk\n\
\x1b[0mProvides you with convinient way of sending CxMessages to Commodities\n\
Recognized commands are:\nDISABLE, ENABLE, APPEAR, DISAPPEAR, KILL.\n\
Commodities' names are case-sensitive!. Use SHOW to list them.\n";
const UBYTE *ver= "$VER: CxCommander " VERSION "";
const char *comms= "disableenableappeardisappearkill";
/* 0123456789 1113151719212325272931
got it? 1012141618202224262830
*/
LONG RC;
struct Library *CxBase;
struct DosLibrary *DOSBase;
int start(void)
{
struct RDArgs *rdargs;
LONG opts[OPT_COUNT];
LONG command;
char ** argptr;
/* let's open libraries, as there is no one to do that for us. */
if(DOSBase=(struct DosLibrary *)OpenLibrary("dos.library", 37L))
{
if(CxBase=OpenLibrary("commodities.library", 37L))
{
memset(opts, 0, sizeof(opts));
/* but command line parsing is OS stuff */
if(rdargs=ReadArgs(TEMPLATE, opts, NULL) )
{
/* does user need help... */
if(opts[OPT_HELP])
Write(Output(), HelpString, sizeof(HelpString));
else
/* ...or wants to see present Commodities? */
if(opts[OPT_SHOW])
TellAllBrokers(NULL);
else
if(opts[OPT_NAME] || opts[OPT_ALL])
{
/* I wanted to have command recognition this fancy way and please don't
change that. */
switch(strstr(comms, strlwr((char *)opts[OPT_COMMAND]))-comms)
{
case 0:
command=CXCMD_DISABLE;
break;
case 7:
command=CXCMD_ENABLE;
break;
case 13:
command=CXCMD_APPEAR;
break;
case 19:
command=CXCMD_DISAPPEAR;
break;
case 28:
command=CXCMD_KILL;
break;
default:
command=NULL;
break;
}
argptr=(char **)opts[OPT_NAME];
if(command!=NULL)
if(opts[OPT_ALL])
/* it's always nice to use self-commenting function names */
TellAllBrokers(command);
else
while(*argptr)
if(BrokerCommand(*(argptr++), command))
RC=RETURN_WARN;
else
RC=RETURN_ERROR;
}
else
RC=RETURN_ERROR;
/* let's clean up after ourselves */
FreeArgs(rdargs);
}
else
{
PrintFault(IoErr(), NULL);
RC=RETURN_FAIL;
}
CloseLibrary(CxBase);
}
else
RC=RETURN_FAIL;
CloseLibrary((struct Library *)DOSBase);
}
else
RC=RETURN_FAIL;
return(RC);
}
/* this routine gets list of available brokers and shows or signals them
depending on the argument passed */
void TellAllBrokers (LONG command)
{
struct List *l;
struct Node *n, *nn;
if (l = AllocMem(sizeof(struct List), MEMF_PUBLIC))
{
/*** generate an empty list ***/
NewList(l);
/*** private function to generate the system broker list ***/
CopyBrokerList(l);
/*** start at head of list ***/
n = l->lh_Head;
if(!n)
RC=RETURN_WARN;
else
while (n && (nn = n->ln_Succ))
{
/*** send command to current broker ***/
if(command)
BrokerCommand((char *)&((struct BrokerCopy *)n)->bc_Name, command);
else
{
Write(Output(), (char *)&((struct BrokerCopy *)n)->bc_Name, strlen((char *)&((struct BrokerCopy *)n)->bc_Name));
Write(Output(), "\n", 1);
}
/*** next node ***/
n = nn;
}
/*** free list and allocated mem ***/
FreeBrokerList(l);
FreeMem(l, sizeof(struct List));
}
}